package com.heng.test.threadLocal;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.alibaba.ttl.TtlRunnable;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class transmittableThreadLocal {
    static TransmittableThreadLocal<String> transmittableThreadLocal = new TransmittableThreadLocal<>();
    public static void main(String[] args) throws InterruptedException {
        ExecutorService threadPool = Executors.newFixedThreadPool(3);


            transmittableThreadLocal.set("idx " + 90);
            System.out.println(transmittableThreadLocal.get());
            threadPool.execute(TtlRunnable.get(() -> {  // 必须要使用这个 TtlRunnable.get()
                System.out.println( "子线程 ---> "+transmittableThreadLocal.get());
                transmittableThreadLocal.set("hello world");
            }));

            Thread.sleep(100);
        System.out.println(transmittableThreadLocal.get());

    }
}
